package com.xxx.Method;

import com.xxx.admin.*;
import com.xxx.admin.Package;
import com.xxx.dao.IBusinessDao;
import com.xxx.dao.IUserdao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class TakeawayMethod {
    Scanner sc = new Scanner(System.in);
    Statement stmt;
    ResultSet rs;
    List<Dishes> ls = new ArrayList<>();
    List<Business> businessloain = new ArrayList();
    List<User> userlogin = new ArrayList();

    public SqlSession link() throws IOException {
        //读取xml文件
        InputStream in = Resources.getResourceAsStream("MybatisConfig.xml");
        //创建sqlsession工厂
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
        //创建链接池
        SqlSession session = factory.openSession();
        return session;
    }
    public void start(){
        try {
            while (true) {
                System.out.println("===========漂亮团外卖系统===========");
                System.out.println("1.登录");
                System.out.println("2.用户注册");
                System.out.println("3.商家注册");
                System.out.println("请输入操作命令:");
                int temp = sc.nextInt();
                switch (temp){
                    case 1:
                        login();
                        break;
                    case 2:
                        userEnroll();
                        break;
                    case 3:
                        businessEnroll();
                        break;
                    default:
                        System.out.println("没有该命令请重新确认");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void userEnroll() {
        try {
            SqlSession session = link();
            System.out.println("请您输入您的用户名");
            String username = sc.next();
            System.out.println("请输入您的密码");
            String password2 = sc.next();
            System.out.println("请输入您的电话");
            String iphone = sc.next();
            System.out.println("请输入您的性别");
            String sex = sc.next();
            System.out.println("请输入您的地址");
            String address = sc.next();
            User user = new User();
            user.setName(username);
            user.setPassword(password2);
            user.setIphone(iphone);
            user.setSex(sex);
            user.setAddress(address);
            IUserdao iUserdao = session.getMapper(IUserdao.class);
            boolean i = iUserdao.addUser(user);
            if(i){
                System.out.println("添加成功");
            }else {
                System.out.println("添加失败");
            }
            session.commit();
            System.out.println("您的id为:"+user.getId());
            session.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void businessEnroll() {
        try {
            SqlSession session = link();
            Business business = new Business();
            System.out.println("请输入您的店长名");
            String name = sc.next();
            System.out.println("请输入您的店名");
            String shopname = sc.next();
            System.out.println("请输入您的密码");
            String password = sc.next();
            System.out.println("请输入您的电话");
            String iphone = sc.next();
            System.out.println("请输入您的地址");
            String address = sc.next();
            business.setName(name);
            business.setShopname(shopname);
            business.setPassword(password);
            business.setIphone(iphone);
            business.setAddress(address);
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            Integer integer = iBusinessDao.addBusiness(business);
            session.commit();
            if (integer>0){
                System.out.println("添加成功!~~");
                System.out.println("您的id为:"+business.getId());
            }
            session.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void login() {
        while (true) {
            System.out.println("请输入:");
            System.out.println("1.用户登录");
            System.out.println("2.商家登录");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    userlogin();
                    return;
                case 2:
                    businesslogin();
                    return;
                default:
                    System.out.println("没有该指令请重新确认!");
            }
        }
    }

    private void businesslogin() {
        try {
            SqlSession session = link();
            while (true) {
                System.out.println("请输入id");
                Integer id = sc.nextInt();
                System.out.println("请输入密码");
                String password = sc.next();
                IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
                Business businesses = iBusinessDao.loginBusiness(id, password);
                if (businesses!=null){
                    businessloain.add(businesses);
                    businessStart();
                    return;
                }else {
                    System.out.println("您输入的账号密码有误请重新确认!~~");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void businessStart() {//登录成功商家界面
        while (true) {
            System.out.println("~~~~商家界面~~~~");
            System.out.println("请输入您的选项:");
            System.out.println("1.员工管理");
            System.out.println("2.分类管理");
            System.out.println("3.菜品管理");
            System.out.println("4.套餐管理");
            System.out.println("5.订单管理");
            System.out.println("6.订单明细管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    employee();
                    break;
                case 2:
                    classify();
                    break;
                case 3:
                    dishes();
                    break;
                case 4:
                    packag();
                    break;
                case 5:
                    orders();
                    break;
                case 6:
                    Details();
                    break;
                case 7:
                    return;
                default:
                    System.out.println("您输入的命令有误请重新确认!~~");
            }
        }
    }

    private void Details() {
        while (true) {
            System.out.println("请输入您的选择:");
            System.out.println("1.增加订单明细");
            System.out.println("2.删除订单明细");
            System.out.println("3.修改订单明细");
            System.out.println("4.查询订单明细");
            System.out.println("5.退出订单明细管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    addDetails();
                    break;
                case 2:
                    deletDetails();
                    break;
                case 3:
                    updateDetails();
                    break;
                case 4:
                    showDetails();
                    break;
                case 5:
                    return;
                default:
                    System.out.println("您输入的指令有误请重新确认!~~");
            }
        }
    }

    private void showDetails() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请您输入您要修改该订单表的订单id");
            Integer did = sc.nextInt();
            System.out.println("请您输入您要修改该订单表的菜品id");
            Integer cid = sc.nextInt();
            System.out.println("请您输入您要修改该订单表的套餐id");
            Integer tid = sc.nextInt();
            OrdersDetails ordersDetails = iBusinessDao.selectOrdersDetails(did, cid, tid);
            System.out.println(ordersDetails);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void updateDetails() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请您输入您要修改该订单表的订单id");
            Integer did = sc.nextInt();
            System.out.println("请您输入您要修改该订单表的菜品id");
            Integer cid = sc.nextInt();
            System.out.println("请您输入您要修改该订单表的套餐id");
            Integer tid = sc.nextInt();
            System.out.println("请输入您要修改的订单名称");
            String name = sc.next();
            System.out.println("请输入要修改的图片");
            String image = sc.next();
            System.out.println("请输入要修改的口味");
            String taste = sc.next();
            System.out.println("请输入修改的数量");
            Integer number = sc.nextInt();
            System.out.println("请输入要修改的金额");
            Double price = sc.nextDouble();
            Integer integer = iBusinessDao.updateOrdersDetails(new OrdersDetails(name, image, did, cid, tid, taste, number, price));
            session.commit();
            session.close();
            if(integer>0){
                System.out.println("修改成功");
            }else {
                System.out.println("您输入的id有误!~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void deletDetails() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请您输入您要删除该订单表的订单id");
            Integer did = sc.nextInt();
            System.out.println("请您输入您要删除该订单表的菜品id");
            Integer cid = sc.nextInt();
            System.out.println("请您输入您要删除该订单表的套餐id");
            Integer tid = sc.nextInt();
            Integer integer = iBusinessDao.deleteOrdersDetails(did, cid, tid);
            session.commit();
            session.close();
            if (integer>0){
                System.out.println("删除成功");
            }else {
                System.out.println("您输入id有误!~");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void addDetails() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请输入您要添加的订单名字");
            String name = sc.next();
            System.out.println("请输入您要添加的订单图片");
            String image = sc.next();
            System.out.println("请输入您要添加的订单id");
            Integer did = sc.nextInt();
            System.out.println("请输入您要添加的菜品id");
            Integer cid = sc.nextInt();
            System.out.println("请输入您要添加的套餐id");
            Integer tid = sc.nextInt();
            System.out.println("请输入您要添加的口味");
            String taste = sc.next();
            System.out.println("请输入要添加的数量");
            Integer number = sc.nextInt();
            System.out.println("请输入要添加的金额");
            Double price = sc.nextDouble();
            Integer integer = iBusinessDao.addOrdersDetails(new OrdersDetails(name, image, did, cid, tid, taste, number, price));
            session.commit();
            session.close();
            if(integer>0){
                System.out.println("添加成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void orders() {
        while (true) {
            System.out.println("请输入您的选择:");
            System.out.println("1.增加订单");
            System.out.println("2.删除订单");
            System.out.println("3.修改订单");
            System.out.println("4.查询订单");
            System.out.println("5.退出订单管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    addorders();
                    break;
                case 2:
                    deletorders();
                    break;
                case 3:
                    updateorders();
                    break;
                case 4:
                    showorders();
                    break;
                case 5:
                    return;
                default:
                    System.out.println("您输入的指令有误请重新确认!~~");
            }
        }
    }

    private void showorders() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            Integer integer = iBusinessDao.showOrders();
            if(integer>0){
                System.out.println("请输入您要查询的订单id");
                Integer id = sc.nextInt();
                List<Orders> orders = iBusinessDao.seleOrders(id);
                for (Orders order : orders) {
                    System.out.println(order);
                }
            }else {
                System.out.println("当前没有任何订单");
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void updateorders() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请输入您要修改的id");
            Integer id = sc.nextInt();
            System.out.println("请输入要修改订单状态");
            String status = sc.next();
            System.out.println("请输入您要修改的订单用户");
            String username = sc.next();
            LocalDateTime time = LocalDateTime.now();
            System.out.println("请输入修改的支付方式");
            Integer method = sc.nextInt();
            System.out.println("请输入要修改实收金额");
            double money = sc.nextDouble();
            System.out.println("请输入您要修改的备注");
            String remark = sc.next();
            System.out.println("请输入您要修改的电话");
            String iphone = sc.next();
            System.out.println("请您输入要修改的地址");
            String address = sc.next();
            Integer integer = iBusinessDao.updateOrders(new Orders(id, status, username, time, method, money, remark, iphone, address, username));
            session.commit();
            session.close();
            if(integer>0){
                System.out.println("修改成功!~");
            }else {
                System.out.println("您输入的id有误!~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void deletorders() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请您输入要删除的订单id");
            Integer id = sc.nextInt();
            Integer integer = iBusinessDao.deleteOrders(id);
            session.commit();
            session.close();
            if (integer>0){
                System.out.println("删除成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void addorders() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请输入该订单的订单用户");
            String name = sc.next();
            LocalDateTime time = LocalDateTime.now();
            System.out.println("请输入支付方式");
            Integer method = sc.nextInt();
            System.out.println("请输入时收金额");
            double money = sc.nextDouble();
            System.out.println("请输入备注");
            String remark = sc.next();
            System.out.println("请输入联系电话");
            String phone = sc.next();
            System.out.println("请输入地址");
            String address = sc.next();
            System.out.println("客户名称");
            String user = sc.next();
            Orders orders = new Orders(null, null, name, time, method, money, remark, phone, address, user);
            Integer integer = iBusinessDao.addOrders(orders);
            session.commit();
            session.close();
            if (integer>0){
                System.out.println("添加成功!~");
                System.out.println("改订单id为:"+orders.getId());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private void packag() {
        while (true) {
            System.out.println("请输入您的选择:");
            System.out.println("1.增加套餐");
            System.out.println("2.删除套餐");
            System.out.println("3.修改套餐");
            System.out.println("4.查询套餐");
            System.out.println("5.退出套餐管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    addpackage();
                    break;
                case 2:
                    deletpackage();
                    break;
                case 3:
                    revisepackage();
                    break;
                case 4:
                    seletpackage();
                    break;
                case 5:
                    return;
                default:
                    System.out.println("您输入的指令有误请重新确认!~~");
            }
        }
    }

    private void seletpackage() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            Integer integer = iBusinessDao.showPackage();
            if(integer>0){
                System.out.println("请输入您要查询的套餐名字");
                String name = sc.next();
                List<Package> packages = iBusinessDao.selectPackage(name);
                System.out.println("套餐信息如下:");
                for (Package aPackage : packages) {
                    System.out.println(aPackage);
                }
            }else {
                System.out.println("当前没有任何套餐!~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void revisepackage() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请输入您要修改的套餐名称");
            String name = sc.next();
            System.out.println("请输入修改后的价格");
            double price = sc.nextDouble();
            System.out.println("请输入修改后的状态");
            Integer status = sc.nextInt();
            System.out.println("请输入修改后的编码");
            String encode = sc.next();
            System.out.println("请输入修改后的描述信息:");
            String description = sc.next();
            System.out.println("请输入修改后的图片");
            String image = sc.next();
            LocalDateTime time = LocalDateTime.now();
            String update = businessloain.get(0).getName();
            Integer integer = iBusinessDao.updatePackage(new Package(null,name,price,status,encode,description,image,null,time,null,update,null));
            session.commit();
            session.close();
            if (integer>0){
                System.out.println("添加成功!~");
            }else {
                System.out.println("您输入的名称和id有误!~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void deletpackage() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请输入您要删除的套餐名称");
            String name = sc.next();
            Integer integer = iBusinessDao.deletePackage(name);
            session.commit();
            session.close();
            if(integer>0){
                System.out.println("删除成功!~");
            }else {
                System.out.println("您输入的套餐名称不存在请重新输入!~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void addpackage() {
        try {
            LocalDateTime time = LocalDateTime.now();
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请输入您要添加的套餐名称");
            String name = sc.next();
            List<Package> packages = iBusinessDao.selePackage(name);
            if (packages!=null&&packages.size()>0){
                Package Package = packages.get(0);
                if (Package.getName().equals(name)){
                    System.out.println("已有该套餐名称请继续为他添加其他菜品");
                    System.out.println("请输入添加的菜品id");
                    Integer id = sc.nextInt();
                    String user = Package.getUpdateUser();
                    Integer integer = iBusinessDao.addPackage(new Package(id, name, Package.getPrice(), null, Package.getEncode(), Package.getDescriptiveInformation(), Package.getImage(), time, time, user, user, null));
                    session.commit();
                    session.close();
                    if (integer>0){
                        System.out.println("添加成功!~");
                    }

                }
            }else {
                System.out.println("请输入菜品id");
                Integer id = sc.nextInt();
                System.out.println("套餐价格");
                Double price = sc.nextDouble();
                System.out.println("请输入该套餐的编码");
                String encode = sc.next();
                System.out.println("请输入描述信息");
                String description = sc.next();
                System.out.println("请输入图片");
                String image = sc.next();
                Business business = businessloain.get(0);
                String user = business.getName();
                Integer integer = iBusinessDao.addPackage(new Package(id, name, price, null, encode, description, image, time, time, user, user, null));
                session.commit();
                session.close();
                if (integer>0){
                    System.out.println("添加成功!~");
                }
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void dishes() {
        while (true) {
            System.out.println("请输入您的选择:");
            System.out.println("1.增加菜品");
            System.out.println("2.删除菜品");
            System.out.println("3.修改菜品");
            System.out.println("4.查询菜品");
            System.out.println("5.退出菜品管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    adddishes();
                    break;
                case 2:
                    deletdishes();
                    break;
                case 3:
                    revisedishes();
                    break;
                case 4:
                    showdishes();
                    break;
                case 5:
                    return;
                default:
                    System.out.println("您输入的指令有误请重新确认!~~");
            }
        }
    }

    private void showdishes() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            Integer integer = iBusinessDao.showDishes();
            if(integer>0){
                System.out.println("请输入菜品id");
                Integer id = sc.nextInt();
                Dishes dishes = iBusinessDao.seleDishes(id);
                if (dishes!=null){
                    System.out.println(dishes);
                }else {
                    System.out.println("当前您输入的菜品id不对!~");
                }
            }else {
                System.out.println("当前没有任何菜品");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void revisedishes() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请输入您要修改的id");
            Integer id = sc.nextInt();
            System.out.println("请输入您要修改的菜品名称");
            String name = sc.next();
            System.out.println("请输入您要修改的菜品价格");
            Double price = sc.nextDouble();
            System.out.println("请输入您要修改的商品码");
            String code = sc.next();
            System.out.println("请输入您要修改的菜品图片");
            String image = sc.next();
            System.out.println("请输入修改后菜品的描述信息");
            String description = sc.next();
            LocalDateTime updatetime = LocalDateTime.now();
            String updatename = businessloain.get(0).getName();
            Integer integer = iBusinessDao.updateDishes(new Dishes(name, id, price, code, image, description, null, null, updatetime, null, updatename, null));
            session.commit();
            session.close();
            if (integer>0){
                System.out.println("修改成功!~");
            }else {
                System.out.println("您输入的id有误!~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void deletdishes() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请输入您要删除的菜品id");
            Integer id = sc.nextInt();
            Integer integer = iBusinessDao.deletDishes(id);
            session.commit();
            session.close();
            if(integer>0){
                System.out.println("删除成功！~");
            }else {
                System.out.println("您输入的id有误!~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void adddishes() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请输入您要添加的菜品名称");
            String name = sc.next();
            System.out.println("请输入您要添加的菜品id");
            Integer id = sc.nextInt();
            System.out.println("请输入您要添加的菜品价格");
            Double price = sc.nextDouble();
            System.out.println("请输入您要添加的商品码");
            String code = sc.next();
            System.out.println("请输入您要添加的菜品图片");
            String image = sc.next();
            System.out.println("请输入该菜品的描述信息");
            String description = sc.next();
            LocalDateTime now = LocalDateTime.now();
            String create = businessloain.get(0).getName();
            Integer integer = iBusinessDao.addDishes(new Dishes(name, id, price, code, image, description, null, now, now, create, create, null));
            session.commit();
            session.close();
            if(integer>0){
                System.out.println("添加成功!~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void classify() {
        while (true) {
            System.out.println("请输入您的选择:");
            System.out.println("1.增加分类");
            System.out.println("2.删除分类");
            System.out.println("3.修改分类");
            System.out.println("4.查询分类");
            System.out.println("5.退出分类管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    addclassify();
                    break;
                case 2:
                    deletclassify();
                    break;
                case 3:
                    reviseclassify();
                    break;
                case 4:
                    showclassify();
                    break;
                case 5:
                    return;
                default:
                    System.out.println("您输入的指令有误请重新确认!~~");
            }
        }
    }

    private void showclassify() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            Integer integer = iBusinessDao.showClassify();
            if(integer>0){
                System.out.println("请输入您要查找的分类id");
                Integer id = sc.nextInt();
                Classify classify = iBusinessDao.seleClassify(id);
                if(classify!=null){
                    System.out.println("当前分类信息为:");
                    System.out.println(classify);
                }else {
                    System.out.println("没有该分类id");
                }
            }else {
                System.out.println("没有任何分类");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void reviseclassify() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请输入您要修改的id号");
            Integer id = sc.nextInt();
            System.out.println("请输入修改后的分类");
            String type = sc.next();
            System.out.println("请输入修改后的分类名称");
            String classname = sc.next();
            LocalDateTime time = LocalDateTime.now();
            Business business = businessloain.get(0);
            String updatename = business.getName();
            Classify classify = new Classify(type, classname, id, null, time, null, updatename);
            Integer integer = iBusinessDao.updateClassify(classify);
            session.commit();
            session.close();
            if(integer>0){
                System.out.println("修改成功!~");
            }else {
                System.out.println("您输入的id有误!~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void deletclassify() {
        try {
            SqlSession session = link();
            System.out.println("请输入您要删除的id");
            Integer id = sc.nextInt();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            Integer integer = iBusinessDao.deleteClassify(id);
            session.commit();
            session.close();
            if(integer>0){
                System.out.println("删除成功!~");
            }else {
                System.out.println("您输入的id有误!~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void addclassify() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            System.out.println("请输入您要添加的分类类型");
            String type = sc.next();
            System.out.println("请输入您要添加的分类名称");
            String classname = sc.next();
            LocalDateTime time = LocalDateTime.now();
            Business business = businessloain.get(0);
            String username = business.getName();
            Classify classify = new Classify(type, classname, null, time, time, username, username);
            Integer integer = iBusinessDao.addClassify(classify);
            session.commit();
            session.close();
            if(integer>0){
                System.out.println("添加成功!~");
                System.out.println("该菜品顺序id:"+classify.getId());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void employee() {
        while (true) {
            System.out.println("请输入您的选择:");
            System.out.println("1.增加员工");
            System.out.println("2.删除员工");
            System.out.println("3.修改员工");
            System.out.println("4.查询员工");
            System.out.println("5.退出员工管理");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    addemployee();
                    break;
                case 2:
                    deltemployee();
                    break;
                case 3:
                    reviseemployee();
                    break;
                case 4:
                    showemployee();
                    break;
                case 5:
                    return;
                default:
                    System.out.println("您输入的指令有误请重新确认!~~");
            }
        }
    }

    private void showemployee() {
        try {
            SqlSession session = link();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            Integer integer = iBusinessDao.showEmployee();
            session.close();
            if(integer<0){
                System.out.println("当前没有任何员工对象!~");
                return;
            }
            SqlSession session1 = link();
            System.out.println("请输入您要查找的员工id");
            Integer id = sc.nextInt();
            IBusinessDao iBusinessDao1 = session1.getMapper(IBusinessDao.class);
            Employee employee = iBusinessDao1.seleEmployee(id);
            System.out.println(employee);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void reviseemployee() {
        try {
            SqlSession session = link();
            System.out.println("请输入您要修改的员工id");
            Integer id = sc.nextInt();
            System.out.println("请输入修改后的名字");
            String name = sc.next();
            System.out.println("请输入修改后的用户名");
            String username = sc.next();
            System.out.println("请输入修改后的密码");
            String password = sc.next();
            System.out.println("请输入修改后的电话");
            String iphone = sc.next();
            System.out.println("请输入修改后的性别");
            String sex = sc.next();
            System.out.println("请输入修改后的身份证");
            String card = sc.next();
            System.out.println("请输入修改后的状态");
            String status = sc.next();
            LocalDateTime time = LocalDateTime.now();
            Business business = businessloain.get(0);
            String update = business.getName();
            Employee employee = new Employee();
            employee.setId(id);
            employee.setName(name);
            employee.setUsername(username);
            employee.setPassword(password);
            employee.setPhone(iphone);
            employee.setSex(sex);
            employee.setIdNumber(card);
            employee.setStatus(status);
            employee.setUpdateTime(time);
            employee.setUpdateUser(update);
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            Integer integer = iBusinessDao.updateEmployee(employee);
            session.commit();
            session.close();
            if (integer>0){
                System.out.println("修改成功!~");
            }else {
                System.out.println("修改失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void deltemployee() {
        try {
            SqlSession session = link();
            System.out.println("请输入该员工的id");
            Integer id = sc.nextInt();
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            Integer integer = iBusinessDao.deleteEmployee(id);
            session.commit();
            session.close();
            if (integer>0){
                System.out.println("删除成功!~");
            }else {
                System.out.println("删除失败!~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void addemployee() {
        try {
            SqlSession session = link();
            System.out.println("请输入员工id");
            Integer id = sc.nextInt();
            System.out.println("请输入员工姓名");
            String name = sc.next();
            System.out.println("请输入员工用户名");
            String username = sc.next();
            System.out.println("请输入员工密码");
            String password = sc.next();
            System.out.println("请输入员工手机号");
            String iphone = sc.next();
            System.out.println("请输入员工性别");
            String sex = sc.next();
            System.out.println("请输入员工身份证号");
            String card = sc.next();
            LocalDateTime time = LocalDateTime.now();
            Business business = businessloain.get(0);
            String CreateUser = business.getName();
            Employee employee = new Employee(id,name,username,password,iphone,sex,card,"1",time,time,CreateUser,CreateUser);
            IBusinessDao iBusinessDao = session.getMapper(IBusinessDao.class);
            Integer integer = iBusinessDao.addEmployee(employee);
            session.commit();
            session.close();
            if (integer>0){
                System.out.println("添加成功!~");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void userlogin() {
            while (true) {
                try {
                    SqlSession session = link();
                    System.out.println("请输入id");
                    Integer id = sc.nextInt();
                    System.out.println("请输入密码");
                    String password = sc.next();
                    IUserdao iUserdao = session.getMapper(IUserdao.class);
                    User user = iUserdao.loginUser(id, password);
                    if(user==null){

                    }
                    userlogin.add(user);
                    session.close();
                    userstart();
                    return;
                } catch (Exception e) {
                    System.out.println("您输入的id或密码不正确请重新输入");
                }
            }
            }

    private void userstart() {
        while (true) {
            User user = userlogin.get(0);
            String name = user.getName();
            System.out.println("欢迎登录:"+name);
            System.out.println("请输入您的选择:");
            System.out.println("1.我要订餐:");
            System.out.println("2.查看订单:");
            System.out.println("3.签收订单:");
            System.out.println("4.删除订单:");
            System.out.println("5.我要点赞:");
            System.out.println("6.退出系统:");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    OrderFood();
                    break;
                case 2:
                    ShowOrder();
                    break;
                case 3:
                    SignOrder();
                    break;
                case 4:
                    deletOrder();
                    break;
                case 5:
                    Thumbsup();
                    break;
                case 6:
                    return;
            }
        }
    }

    private void Thumbsup() {//点赞因为在数据库中没有设置该类型所以先省略了
    }

    private void deletOrder() {
        try {
            SqlSession session = link();
            System.out.println("请输入您要删除的订单id");
            Integer id = sc.nextInt();
            IUserdao iUserdao = session.getMapper(IUserdao.class);
            List<Orders> orders = iUserdao.signOrders();
            for (Orders order : orders) {
                if (order.getOrdersStatus().equals("4")&&id.equals(order.getId())){
                    iUserdao.dateOrders(id);
                    session.commit();
                    session.close();
                    return;
                }else if(id.equals(order.getId())){
                    System.out.println(order.getOrdersStatus());
                    System.out.println("您确定要删除吗?   y/n");
                    String yn = sc.next();
                    switch (yn){
                        case "y":
                            iUserdao.dateOrders(id);
                            session.commit();
                            session.close();

                        case "n":
                            return;
                    }
                }
            }
            System.out.println("没有该id");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private void SignOrder() {
        try {
            System.out.println("请输入您要签收的订单id");
            Integer id = sc.nextInt();
            SqlSession session = link();
            IUserdao iUserdao = session.getMapper(IUserdao.class);
            Integer integer = iUserdao.updateOrders(id);
            if(integer>0){
                System.out.println("修改成功!");
            }
            session.commit();
            session.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void ShowOrder() {
        try {
            SqlSession session = link();
            IUserdao iUserdao = session.getMapper(IUserdao.class);
            List<UserOrders> orders = iUserdao.showOrders();
            if (orders!=null){
                for (UserOrders order : orders) {
                    System.out.print(order.getId()+"  ");
                    System.out.print(order.getUser()+"  ");
                    System.out.print(order.getName()+"  ");
                    System.out.print(order.getQuantity()+"  ");
                    System.out.print(order.getCheckoutTime()+"  ");
                    System.out.print(order.getAddress()+"  ");
                    System.out.print(order.getOrders_status()+"  ");
                    System.out.println(order.getMoney());
                }
            }else {
                System.out.println("当前没有任何订单!~~");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private void OrderFood() {
        try {
            SqlSession session = link();
            IUserdao iUserdao = session.getMapper(IUserdao.class);
            List<Dishes> dishes = iUserdao.showDishes();
            if(dishes!=null){
                System.out.println("当前菜单如下:");
                for (Dishes dish : dishes) {
                    System.out.print("菜品id:"+dish.getCid()+"  ");
                    System.out.print("菜品名称:"+dish.getName()+"  ");
                    System.out.print("菜品价格:"+dish.getPrice()+"  ");
                    System.out.print("菜品二维码:"+dish.getProductCode()+"  ");
                    System.out.print("菜品图片:"+dish.getImage()+"  ");
                    System.out.println("菜品描述:"+dish.getDescription()+"  ");
                }
            }
            IUserdao into_orders = session.getMapper(IUserdao.class);
            System.out.println("请输入您要点的菜品id");
            Integer id = sc.nextInt();
            for (Dishes dish : dishes) {
                if (dish.getCid().equals(id)){
                    System.out.println("请输入您的备注");
                    String remark = sc.next();
                    System.out.println("请输入您要多少份");
                    Integer num = sc.nextInt();
                    Double sum = dish.getPrice()*num;
                    if (sum>=50){
                    }else {
                        sum += sum+6;
                    }
                    Orders orders = new Orders();
                    User user = userlogin.get(0);
                    orders.setUser(user.getName());
                    orders.setCheckoutTime(LocalDateTime.now());
                    orders.setPaymentMethods(1);
                    orders.setMoney(sum);
                    orders.setRemark(remark);
                    orders.setPhone(user.getIphone());
                    orders.setAddress(user.getAddress());
                    orders.setUserName(user.getName());
                    into_orders.intoOrders(orders);
                    session.commit();
                    Integer  Orders_id= orders.getId();
                    System.out.println("您的订单id为："+Orders_id);
                    OrdersDetails orders_details = new OrdersDetails();
                    orders_details.setName(user.getName());
                    orders_details.setImage("1");
                    orders_details.setOrder(Orders_id);
                    orders_details.setDishes(id);
                    orders_details.setSetmeal(0);
                    orders_details.setTaste(remark);
                    orders_details.setQuantity(num);
                    orders_details.setMoney(sum);
                    IUserdao into_details = session.getMapper(IUserdao.class);
                    into_details.intoDetails(orders_details);
                    session.commit();
                    session.close();
                    return;
                }
            }
            System.out.println("没有当前菜品id请重新确认!~~");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
